<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="项目名称" class="row-padding-bottom">
              <el-input
                v-model="filterField.projectName"
                placeholder="请输入项目名称"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="区域" class="row-padding-bottom">
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                clearable
                filterable
                :props="{ checkStrictly: true }"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="行业" class="row-padding-bottom">
                <el-select
                  v-model="filterField.industryId"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in industryOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.status"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in statusOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="投资类型" class="row-padding-bottom">
                <el-select
                  v-model="filterField.investment"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in investmentOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="公示状态" class="row-padding-bottom">
                <el-select
                  v-model="filterField.state"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in stateOptions"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="申请日期" class="row-padding-bottom">
                <timeSelection
                  @getStartTimeValue="getStartTimeValue"
                  @getEndTimeValue="getEndTimeValue"
                ></timeSelection>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item>
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <el-button
                v-hasBtn="'nobackpayProject:export'"
                type="primary"
                icon="icon iconfont icondaochu"
                @click="exportExcel"
                class="commonBtn saveBtn funComBut"
                >导出</el-button
              >
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          @sort-change="sortChange"
          :data="tableList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          v-loading="loading"
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="projectName"
            label="项目名称"
            width="230"
            fixed="left"
          >
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="areaName"
            label="区域"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="industryName"
            label="行业"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="statusName"
            label="状态"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="investmentName"
            label="投资类型"
            align="center"
            :formatter="formatTd"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="stateName"
            label="公示状态"
            align="center"
            :formatter="formatTd"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="noNum"
            label="已确认人数"
            align="center"
            :formatter="formatTd"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="yesNum"
            label="投诉人数"
            align="center"
            :formatter="formatTd"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            sortable="custom"
            label="公示申请日期"
            align="center"
            :formatter="formatTd"
            width="180"
          ></el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import common from '../../kits/common'
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'nobackpayProject',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '无欠薪公示项目列表',
      stateOptions: [],
      tableList: [],
      requestUrl: 'api-r/noarrearspublicity/expand/list',
      areaId: '', //区域
      //搜索条件
      filterField: {
        projectName: '',
        areaId: '',
        industryId: '',
        status: '',
        investment: '',
        state: '',
        createDateStart: '',
        createDateEnd: '',
      },
      loading: false,
      isShow: false,
      advanced: false,
    }
  },
  computed: {
    ...mapState([
      'areasOptions',
      'industryOptions',
      'investmentOptions',
      'statusOptions',
    ]),
  },
  mounted() {
    this.getStates()
    this.$nextTick(() => {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    // 公示状态
    getStates() {
      return this.axios({
        method: 'post',
        url: 'api-r/noarrearspublicity/expand/noarrearsstate',
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.stateOptions = response.data.result
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    // 列表
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },
    getStartTimeValue(val) {
      if (val) {
        this.filterField.createDateStart = val
      } else {
        this.filterField.createDateStart = ''
      }
    },
    getEndTimeValue(val) {
      if (val) {
        this.filterField.createDateEnd = val
      } else {
        this.filterField.createDateEnd = ''
      }
    },
    // 是否有导出数据
    getExports() {
      return this.axios({
        method: 'post',
        url: 'api-r/noarrearspublicity/expand/list',
        data: this.filterField,
      })
        .then((response) => {
          if (!response.data.hasError) {
            return response.data.result.results &&
              response.data.result.results.length > 0
              ? true
              : false
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    // 导出
    async exportExcel() {
      const flag = await this.getExports()
      const {
        projectName,
        areaId,
        industryId,
        status,
        investment,
        state,
        createDateStart,
        createDateEnd,
        sortField,
        sort,
      } = this.filterField
      if (flag) {
        window.location.href =
          common.commonApi +
          'api-r/noarrearspublicity/expand/noarrearspublicityexport?projectName=' +
          projectName +
          '&areaId=' +
          areaId +
          '&industryId=' +
          industryId +
          '&status=' +
          status +
          '&investment=' +
          investment +
          '&state=' +
          state +
          '&createDateStart=' +
          createDateStart +
          '&createDateEnd=' +
          createDateEnd +
          '&sortField=' +
          sortField +
          '&sort=' +
          sort +
          '&access_token=' +
          localStorage.getItem('access_token')
      } else {
        this.$message.warning('暂无数据导出')
      }
    },
  },
}
</script>
<style lang="less" scoped>
.mainCon {
  top: 197px;
}
.saveBtn /deep/ .iconfont {
  padding: 0 5px;
  font-size: 14px;
}
</style>
